<template>
  <div>
    <a-table
      bordered
      :columns="columns"
      :dataSource="tableData"
      :loading="loading"
      :rowKey="record => record.id"
      :pagination="false"
    >
      <span slot="action" slot-scope="text,record">
        <span v-action="'sys:user:update'">
          <a href="javascript:;" @click="edit(record)">编辑</a>
          <a-divider type="vertical" />
        </span>
        <span v-action="'sys:user:update'">
          <a href="javascript:;" @click="deleteItem(record)">删除</a>
        </span>
      </span>
    </a-table>
  </div>
</template>

<script>
import { TableMixin } from '@/mixins/TableMixin'
import { treeList, deleteObj } from '@/api/cms/cmsMenus'
export default {
  name: 'MenusList',
  mixins: [TableMixin],
  data () {
    return {
      queryParam: {
        name: ''
      },
      loading: false,
      tableData: [],
      columns: [
        {
          title: '名称',
          dataIndex: 'name'
        },
        {
          title: '地址',
          dataIndex: 'url'
        },
        {
          title: '排序',
          dataIndex: 'priority'
        },
        {
          title: '操作',
          width: '200px',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  methods: {
    init () {
      this.loading = true
      treeList().then(res => {
        this.tableData = res.data
        this.loading = false
      })
    },
    edit (record) {
      this.$emit('parentFn2', { id: record.id, type: 'edit' })
    },
    deleteItem (record) {
      deleteObj(record.id).then(res => {
        this.init()
      })
    },
    frush () {
      this.init()
    }
  },
  created () {
    this.init()
  }
}
</script>

<style scoped>

</style>
